﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

namespace NinjaToolbox
{
    public abstract class ComponentBase : MonoBehaviour
    {
        protected float mBirthTime;
        protected bool mIsDestroying;

        public event Action OnAwakeCallback;
        public event Action OnEnableCallback;
        public event Action OnDisableCallback;
        public event Action OnDestroyCallback;

        public float BirthTime { get { return mBirthTime; } }


        /// <summary>
        /// Nothing do anything.
        /// </summary>
        protected virtual void OnGUI_Imple()
        {

        }

#if ENABLE_IMGUI
        void OnGUI()
        {
            OnGUI_Imple();
        }
#endif

        protected virtual void Awake()
        {
            RecordBirthTime();

            if (OnAwakeCallback != null) OnAwakeCallback();
        }

        protected virtual void OnEnable()
        {
            if (OnEnableCallback != null) OnEnableCallback();
        }

        /// <summary>
        /// Nothing do anything.
        /// </summary>
        protected virtual void OnDisable()
        {
            if (OnDisableCallback != null) OnDisableCallback();
        }

        /// <summary>
        /// Nothing do anything.
        /// </summary>
        protected virtual void OnDestroy()
        {
            mIsDestroying = true;

            if (OnDestroyCallback != null) OnDestroyCallback();
        }

        protected virtual void RecordBirthTime()
        {
            mBirthTime = Time.time;
        }
    }
}